<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户" prop="userNick">
        <el-input
          v-model="queryParams.userNick"
          placeholder="请输入用户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月份">
           <el-date-picker
             type="monthrange"
             v-model="monthRange"
             value-format="yyyy-MM-dd"
             placeholder="选择一个或多个月">
           </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="monthofcList" @selection-change="handleSelectionChange">
      <el-table-column label="用户" align="center" prop="userNick" fixed />
      <el-table-column label="日期" align="center" prop="ofcmpayMonth" >
        <template slot-scope="scope">
          <span>{{ scope.row.ofcmpayYear + "-" + scope.row.ofcmpayMonth }}</span>
        </template>
      </el-table-column>
      <el-table-column label="底薪" align="center" prop="basicSalary" />
      <el-table-column label="岗薪" align="center" prop="postPay" />
      <el-table-column label="职称" align="center" prop="gradePay" />
      <el-table-column label="学历" align="center" prop="educationPay" />
      <el-table-column label="考勤补贴" align="center" prop="workAllowance" />
      <el-table-column label="个人绩效比例" align="center" prop="personalPerformance" />
      <el-table-column label="部门绩效比例" align="center" prop="deptPerformance" />
      <el-table-column label="每月固定" align="center" prop="fixedSalary" />
      <el-table-column label="全面薪酬" align="center" prop="totalReward" />
      <el-table-column label="餐补" align="center" prop="mealAllowance" />
      <el-table-column label="高温补贴" align="center" prop="highTemperature" />
      <el-table-column label="早班补助" align="center" prop="earlyShift" />
      <el-table-column label="晚班补助" align="center" prop="nightShift" />
      <el-table-column label="加班补助" align="center" prop="overtimeAllallowance" />
      <el-table-column label="应发工资" align="center" prop="wagePayable" />
      <el-table-column label="公积金" align="center" prop="providentFund" />
      <el-table-column label="社保" align="center" prop="socialSecurity" />
      <el-table-column label="代扣税" align="center" prop="taxDeduction" />
      <el-table-column label="每月实发" align="center" prop="netSalary" />
      <el-table-column label="满勤天数" align="center" prop="fullDay" />
      <el-table-column label="出勤天数" align="center" prop="attendanceDay" />
      <el-table-column label="缺勤天数" align="center" prop="absenceDay" />
      <el-table-column label="出勤固定" align="center" prop="attendancePay" />
      <el-table-column label="操作" fixed="right" align="center" width="150" class-name="small-padding fixed-width">
        <template slot-scope="scope">
           <el-button
             size="mini"
             type="text"
             icon="el-icon-edit"
             @click="handleDetail(scope.row)"
             v-hasPermi="['sl:monthofc:query']"
           >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改行政固定工资对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="用户" prop="userNick">
              {{form.userNick}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="日期" prop="ofcmpayYear">
              {{form.ofcmpayYear + '-' + form.ofcmpayMonth}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="底薪" prop="basicSalary">
              {{form.basicSalary}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="考勤补贴" prop="workAllowance">
              {{form.workAllowance}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="职级" prop="levelPay">
              {{form.levelPay}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="岗薪" prop="postPay">
              {{form.postPay}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="职称" prop="gradePay">
              {{form.gradePay}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="学历" prop="educationPay">
              {{form.educationPay}}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="每月固定" prop="fixedSalary">
              {{form.fixedSalary}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="全面薪酬" prop="totalReward">
              {{form.totalReward}}
            </el-form-item>
          </el-col>
          <el-col :span="6">

          </el-col>
          <el-col :span="6">

          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="满勤天数" prop="fullDay">
              {{form.fullDay}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="出勤天数" prop="attendanceDay">
              {{form.attendanceDay}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="缺勤天数" prop="absenceDay">
              {{form.absenceDay}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="出勤固定" prop="attendancePay">
              {{form.attendancePay}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="工龄工资" prop="ageAllpay">
              {{form.ageAllpay}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="餐补" prop="mealAllowance">
              {{form.mealAllowance}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="高温补贴" prop="highTemperature">
              {{form.highTemperature}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="加班补助" prop="overtimeAllallowance">
              <el-input v-model="form.overtimeAllallowance" class="def-input-number" type="number" placeholder="请输入加班补助" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="早班次数" prop="earlyNum">
              <el-input v-model="form.earlyNum" @change="handleEarly" class="def-input-number" type="number" placeholder="请输入早班次数" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="早班补助" prop="earlyShift">
              {{form.earlyShift}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="晚班次数" prop="nightNum">
              <el-input v-model="form.nightNum" @change="handleNight" class="def-input-number" type="number" placeholder="请输入晚班次数" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="晚班补助" prop="nightShift">
              {{form.nightShift}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="应发工资" prop="wagePayable">
              {{form.wagePayable}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="公积金" prop="providentFund">
              {{form.providentFund}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="社保" prop="socialSecurity">
              {{form.socialSecurity}}
             </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="代扣税" prop="taxDeduction">
              {{form.taxDeduction}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="每月实发" prop="netSalary">
          {{form.netSalary}}
        </el-form-item>
        <div v-if="form.slOfcLeave!=null">
          <el-divider content-position="center">请假信息</el-divider>
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="事假">
                        {{form.slOfcLeave.leaveAbsenceNum}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="工伤假">
                        {{form.slOfcLeave.injuryLeaveNum}}

                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="工伤假工资">
                        {{form.slOfcLeave.injuryLeavePay}}

                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="病假">
                        {{form.slOfcLeave.sickLeaveNum}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="病假工资">
                        {{form.slOfcLeave.sickLeavePay}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="婚假">
                        {{form.slOfcLeave.marriageLeaveNum}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="婚假工资">
                        {{form.slOfcLeave.marriageLeavePay}}

                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="丧假">
                        {{form.slOfcLeave.bereavementLeaveNum}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="丧假工资">
                        {{form.slOfcLeave.bereavementLeavePay}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="产假">
                        {{form.slOfcLeave.maternityLeaveNum}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="产假工资">
                        {{form.slOfcLeave.maternityLeavePay}}
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="陪产假">
                        {{form.slOfcLeave.paternityLeaveNum}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="陪产假工资">
                        {{form.slOfcLeave.paternityLeavePay}}
                      </el-form-item>
                    </el-col>
                  </el-row>
        </div>
          <div v-if="form.slOfcperformance!=null">
            <el-divider content-position="center">绩效信息</el-divider>
            <el-row>
              <el-col :span="6">
                <el-form-item label="绩效天数">
                  {{form.slOfcperformance.performanceDay}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="缺勤天数">
                  {{form.slOfcperformance.absenceDay}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="绩效基数">
                  {{form.slOfcperformance.performanceBase}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="扣发绩效">
                  {{form.slOfcperformance.performanceDeduction}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="工作绩效">
                  {{form.slOfcperformance.deduction}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="剩余绩效">
                  {{form.slOfcperformance.performanceResidue}}
                </el-form-item>
              </el-col>
            </el-row>
          </div>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">更 新</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listMonthofcRange, listMonthofc, getMonthofc, delMonthofc, addMonthofc, updateMonthofc } from "@/api/sl/monthofc";

export default {
  name: "MonthofcReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedSlLeaveRecord: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 行政固定工资表格数据
      monthofcList: [],
      // 请假记录表格数据
      slLeaveRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        userNick: null,
        deptId: null,
        ofcmpayYear: null,
        ofcmpayMonth: null,
        isHistory: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      monthRange:[],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询行政固定工资列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.monthRange && '' != this.monthRange) {
        this.queryParams.params["startMonth"] = this.monthRange[0];
        this.queryParams.params["endMonth"] = this.monthRange[1];
      }
      this.queryParams.isHistory = "0";
      listMonthofcRange(this.queryParams).then(response => {
        this.monthofcList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ofcmpayId: null,
        userName: null,
        userNick: null,
        deptId: null,
        ofcmpayYear: null,
        ofcmpayMonth: null,
        ofcmpayStart: null,
        ofcmpayEnd: null,
        basicSalary: null,
        levelPay: null,
        postPay: null,
        gradePay: null,
        educationPay: null,
        workAllowance: null,
        personalPerformance: null,
        deptPerformance: null,
        fixedSalary: null,
        totalReward: null,
        workingAge: null,
        ageBase: null,
        ageAllpay: null,
        agePay: null,
        mealAllowance: null,
        mealBase: null,
        highTemperature: null,
        earlyNum: null,
        earlyBase: null,
        earlyShift: null,
        nightNum: null,
        nightBase: null,
        nightShift: null,
        overtimeAllallowance: null,
        overtimeAllowance: null,
        wagePayable: null,
        providentFund: null,
        socialSecurity: null,
        taxDeduction: null,
        netSalary: null,
        fullDay: null,
        attendanceDay: null,
        absenceDay: null,
        attendancePay: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.slLeaveRecordList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ofcmpayId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      this.reset();
      const ofcmpayId = row.ofcmpayId || this.ids
      getMonthofc(ofcmpayId).then(response => {
        this.form = response.data;
        this.slLeaveRecordList = response.data.slLeaveRecordList;
        this.open = true;
        this.title = "行政固定工资明细";
      });
    },
	/** 请假记录序号 */
    rowSlLeaveRecordIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },

    /** 复选框选中数据 */
    handleSlLeaveRecordSelectionChange(selection) {
      this.checkedSlLeaveRecord = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sl/monthofc/export', {
        ...this.queryParams
      }, `monthofc_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
